package com.loan.web.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.loan.entity.Mortgage;
import com.loan.entity.ResponseResult;
import com.loan.service.MortgageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.naming.spi.ResolveResult;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/mortgage")
public class MortgageController {
    @Autowired
    private MortgageService mortgageService;

    /**
     * 添加资产
     */
    @RequestMapping("/add")
    public ResponseResult<Void> add(@RequestBody Mortgage mortgage){
        log.info("添加资产");
        log.info("parm:"+mortgage.toString());
        mortgageService.save(mortgage);
        return ResponseResult.SUCCESS;
    }


    /**
     * 获取客户资产
     * @param cusId
     * @return
     */
    @RequestMapping("/byCid/{cusId}")
    public ResponseResult<List<Mortgage>> getByCid(@PathVariable Integer cusId){
        log.info("获取客户的资产");
        log.info("cid:"+cusId);
        QueryWrapper<Mortgage> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("cus_id",cusId);
        List<Mortgage> mortgages = mortgageService.list(queryWrapper);
        return new ResponseResult<>(mortgages);
    }


    /**
     * 条件查询
     * @param mortgage
     * @return
     */
    @RequestMapping("/condition")
    public ResponseResult<List<Mortgage>> condition(@RequestBody Mortgage mortgage){
        log.info("\n--------------------条件查询--------------------\n参数:{}",mortgage);
        List<Mortgage> mortgages = mortgageService.condition(mortgage);
        return new ResponseResult<>(mortgages);
    }



}
